
<!DOCTYPE html>
<html lang="">


<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <meta name="theme-color" content="#202020">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <script src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>
  
  
    <meta name="keywords" content="微信小程序,">
  

  
    <meta name="description" content="微信小程序打夯之旅(六)：支付流程">
  
  
  <link rel="icon" type="image/x-icon" href="/logo.png">
  <title>微信小程序打夯之旅(六)：支付流程 [ 复制粘贴工程师 ]</title>
  
    <!-- stylesheets list from config.yml -->
    
      <link rel="stylesheet" href="//cdn.bootcss.com/pure/1.0.0/pure-min.css">
    
      <link rel="stylesheet" href="/css/xoxo.css">
    
  
</head>


<body>
  <div class="nav-container">
    <nav class="home-menu pure-menu pure-menu-horizontal">
  <a class="pure-menu-heading" href="/">
    <img class="avatar" src="https://wx.qlogo.cn/mmopen/vi_32/AMpRacDgkTPogKk4gQ5IC3QezP55XoPpicQpnD9Vz3eNz6OPFYyFrFzCa4EGQGH65kPia5YJwQBBvvJpVwQ4lfVg/132">
    <span class="title">复制粘贴工程师</span>
  </a>

  <ul class="pure-menu-list clearfix">
      
          
            <li class="pure-menu-item"><a href="/" class="pure-menu-link">首页</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/search" class="pure-menu-link">搜索</a></li>
          
      
  </ul>

</nav>
  </div>

  <div class="container" id="content-outer">
    <div class="inner" id="content-inner">
      <div class="post-container">
  <article class="post" id="post">
    <header class="post-header text-center">
      <h1 class="title">
        微信小程序打夯之旅(六)：支付流程
      </h1>
      <span>
        
        <time class="time" datetime="2019-03-28T09:01:50.000Z">
        2019-03-28
      </time>
        
      </span>
      <span class="slash">/</span>
      <span class="post-meta">
      <span class="post-tags">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/微信小程序/">微信小程序</a></li></ul>
      </span>
    </span>
      <span class="slash">/</span>
      <span class="read">
      <span id="busuanzi_value_page_pv"></span> 点击
    </span>
      <span class="slash">/</span>
    </header>

    <div class="post-content">
      <h4 id="支付流程示意图"><a href="#支付流程示意图" class="headerlink" title="支付流程示意图"></a>支付流程示意图</h4><ol>
<li>预支付（请求后台，后台请求微信服务获取支付信息）</li>
<li>调用 <code>API</code> 发起支付：<code>wx.requestPayment({})</code></li>
</ol>
<a id="more"></a>
<p><img src="https://pay.weixin.qq.com/wiki/doc/api/img/wxa-7-2.jpg" alt="image"></p>
<h4 id="jsAPI、jsSDK、小程序支付的对比-开发步骤"><a href="#jsAPI、jsSDK、小程序支付的对比-开发步骤" class="headerlink" title="jsAPI、jsSDK、小程序支付的对比(开发步骤)"></a>jsAPI、jsSDK、小程序支付的对比(开发步骤)</h4><table>
<thead>
<tr>
<th>对比栏目</th>
<th>JSAPI</th>
<th>JSSDK</th>
<th>小程序</th>
</tr>
</thead>
<tbody>
<tr>
<td>统一下单</td>
<td>都需要先获取到Openid，调用相同的API</td>
<td>同</td>
<td>同</td>
</tr>
<tr>
<td>调起数据签名</td>
<td>五个字段参与签名(区分大小写)：appId,nonceStr,package,signType,timeStamp</td>
<td>同</td>
<td>同</td>
</tr>
<tr>
<td>调起支付页面协议</td>
<td>HTTP或HTTPS</td>
<td>HTTP或HTTPS</td>
<td>HTTPS</td>
</tr>
<tr>
<td>支付目录</td>
<td>有</td>
<td>有</td>
<td>无</td>
</tr>
<tr>
<td>授权域名</td>
<td>有</td>
<td>有</td>
<td>无</td>
</tr>
<tr>
<td>回调函数</td>
<td>有</td>
<td>success回调</td>
<td>complete、fail、success回调函数</td>
</tr>
</tbody>
</table>
<h4 id="小程序调起支付-API-说明"><a href="#小程序调起支付-API-说明" class="headerlink" title="小程序调起支付 API 说明"></a>小程序调起支付 <code>API</code> 说明</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">wx.requestPayment(</span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">'timeStamp'</span>: <span class="string">''</span>,</span><br><span class="line">  <span class="string">'nonceStr'</span>: <span class="string">''</span>,</span><br><span class="line">  <span class="string">'package'</span>: <span class="string">''</span>,</span><br><span class="line">  <span class="string">'signType'</span>: <span class="string">'MD5'</span>,</span><br><span class="line">  <span class="string">'paySign'</span>: <span class="string">''</span>,</span><br><span class="line">  <span class="string">'success'</span>:<span class="function"><span class="keyword">function</span>(<span class="params">res</span>)</span>&#123;&#125;,</span><br><span class="line">  <span class="string">'fail'</span>:<span class="function"><span class="keyword">function</span>(<span class="params">res</span>)</span>&#123;&#125;,</span><br><span class="line">  <span class="string">'complete'</span>:<span class="function"><span class="keyword">function</span>(<span class="params">res</span>)</span>&#123;&#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<ul>
<li><code>paySign</code> 字段包含信息说明：</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">paySign = MD5(appId=wxd678efh567hg6787&amp;nonceStr=<span class="number">5</span>K8264ILTKCH16CQ2502SI8ZNMTM67VS&amp;package=prepay_id=wx2017033010242291fcfe0db70013231072&amp;signType=MD5&amp;timeStamp=<span class="number">1490840662</span>&amp;key=qazwsxedcrfvtgbyhnujmikolp111111) = <span class="number">22</span>D9B4E54AB1950F51E0649E8810ACD6</span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th>字段名</th>
<th>变量名</th>
<th>必填</th>
<th>类型</th>
<th>示例值</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>小程序ID</td>
<td>appId</td>
<td>是</td>
<td>String</td>
<td>wx***6787</td>
<td>微信分配的小程序ID</td>
</tr>
<tr>
<td>时间戳</td>
<td>timeStamp</td>
<td>是</td>
<td>String</td>
<td>14***662</td>
<td>时间戳从1970年1月1日00:00:00至今的秒数,即当前的时间</td>
</tr>
<tr>
<td>随机串</td>
<td>nonceStr</td>
<td>是</td>
<td>String</td>
<td>5K***67VS</td>
<td>随机字符串，不长于32位。推荐随机数生成算法</td>
</tr>
<tr>
<td>数据包</td>
<td>package</td>
<td>是</td>
<td>String</td>
<td>prepay_id=wx***1072</td>
<td>统一下单接口返回的 prepay_id 参数值，提交格式如：prepay_id=wx**1072</td>
</tr>
<tr>
<td>签名方式</td>
<td>signType</td>
<td>是</td>
<td>String</td>
<td>MD5</td>
<td>签名类型，默认为MD5，支持HMAC-SHA256和MD5。注意此处需与统一下单的签名类型一致</td>
</tr>
</tbody>
</table>
<ul>
<li>参数说明：</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>必填</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>timeStamp</td>
<td>String</td>
<td>是</td>
<td>时间戳从1970年1月1日00:00:00至今的秒数,即当前的时间</td>
</tr>
<tr>
<td>nonceStr</td>
<td>String</td>
<td>是</td>
<td>随机字符串，长度为32个字符以下。</td>
</tr>
<tr>
<td>package</td>
<td>String</td>
<td>是</td>
<td>统一下单接口返回的 prepay_id 参数值，提交格式如：prepay_id=*</td>
</tr>
<tr>
<td>signType</td>
<td>String</td>
<td>是</td>
<td>签名类型，默认为MD5，支持HMAC-SHA256和MD5。注意此处需与统一下单的签名类型一致</td>
</tr>
<tr>
<td>paySign</td>
<td>String</td>
<td>是</td>
<td>签名,具体签名方案参见微信公众号支付帮助文档;</td>
</tr>
<tr>
<td>success</td>
<td>Function</td>
<td>否</td>
<td>接口调用成功的回调函数</td>
</tr>
<tr>
<td>fail</td>
<td>Function</td>
<td>否</td>
<td>接口调用失败的回调函数</td>
</tr>
<tr>
<td>complete</td>
<td>Function</td>
<td>否</td>
<td>接口调用结束的回调函数（调用成功、失败都会执行）</td>
</tr>
</tbody>
</table>
<ul>
<li>回调说明：</li>
</ul>
<table>
<thead>
<tr>
<th>回调类型</th>
<th>errMsg</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>success</td>
<td>requestPayment:ok</td>
<td>调用支付成功</td>
</tr>
<tr>
<td>fail</td>
<td>requestPayment:fail cancel</td>
<td>用户取消支付</td>
</tr>
<tr>
<td>fail</td>
<td>requestPayment:fail (detail message)</td>
<td>调用支付失败，其中 detail message 为后台返回的详细失败原因</td>
</tr>
</tbody>
</table>
<h4 id="预支付流程"><a href="#预支付流程" class="headerlink" title="预支付流程"></a>预支付流程</h4><p>前端提交需支付的信息到开发者服务器，开发者服务器再提交到微信，而后返回需要的信息<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">"sign"</span>:<span class="string">"A2****************A6"</span>,</span><br><span class="line"></span><br><span class="line">    <span class="string">"timestamp"</span>:<span class="string">"14****************68"</span>,</span><br><span class="line"></span><br><span class="line">    <span class="string">"package"</span>:<span class="string">"Sign=WXPay"</span>,</span><br><span class="line"></span><br><span class="line">    <span class="string">"partnerId"</span>:<span class="string">"14****************02"</span>,</span><br><span class="line"></span><br><span class="line">    <span class="string">"appid"</span>:<span class="string">"wx****************ab"</span>,</span><br><span class="line"></span><br><span class="line">    <span class="string">"nonceStr"</span>:<span class="string">"9f****************37"</span>,</span><br><span class="line"></span><br><span class="line">    <span class="string">"prepayId"</span>:<span class="string">"wx****************54"</span></span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="发起支付"><a href="#发起支付" class="headerlink" title="发起支付"></a>发起支付</h4><p>md5下载链接：<a href="https://code.csdn.net/snippets/2019875/master/download" target="_blank" rel="noopener">https://code.csdn.net/snippets/2019875/master/download</a><br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> MD5Util = <span class="built_in">require</span>(<span class="string">'../../../utils/md5.js'</span>);</span><br><span class="line"><span class="keyword">var</span> sign = <span class="string">''</span>;</span><br><span class="line"><span class="keyword">var</span> signA = <span class="string">"appId="</span>+app.appId+<span class="string">"&amp;nonceStr="</span>+res.data.nonceStr+<span class="string">"&amp;package=prepay_id="</span>+res.data.prepayId+<span class="string">"&amp;signType=MD5&amp;timeStamp="</span>+res.data.timestamp;</span><br><span class="line"><span class="keyword">var</span> signB = signA+<span class="string">"&amp;key="</span>+app.key;</span><br><span class="line">sign = MD5Util.MD5(signB).toUpperCase();</span><br><span class="line"></span><br><span class="line">wx.requestPayment(&#123;</span><br><span class="line">    nonceStr: res.data.nonceStr,</span><br><span class="line">    package: <span class="string">"prepay_id="</span>+res.data.prepayId,</span><br><span class="line">    signType: <span class="string">'MD5'</span>,</span><br><span class="line">    timeStamp: res.data.timestamp,</span><br><span class="line">    paySign: sign,</span><br><span class="line">    success: <span class="function"><span class="keyword">function</span>(<span class="params">res</span>)</span>&#123;</span><br><span class="line">      <span class="built_in">console</span>.log(<span class="string">"支付成功"</span>);</span><br><span class="line">    &#125;,</span><br><span class="line">    fail: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    &#125;,</span><br><span class="line">    complete: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></p>
<h4 id="代码Demo"><a href="#代码Demo" class="headerlink" title="代码Demo"></a>代码Demo</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">wx.request(&#123;</span><br><span class="line">  url: <span class="string">'https://调用服务器获取微信统一下单数据'</span>,</span><br><span class="line">  method: <span class="string">'GET'</span>,</span><br><span class="line">  data: &#123; <span class="attr">uid</span>: uid, <span class="attr">id</span>: id &#125;,</span><br><span class="line">  success: <span class="function"><span class="keyword">function</span> (<span class="params">res</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> nowTime = <span class="keyword">new</span> <span class="built_in">Date</span>()</span><br><span class="line">    <span class="keyword">var</span> appId = res.data.appid</span><br><span class="line">    <span class="keyword">var</span> timeStamp1 = <span class="built_in">Math</span>.round((nowTime.getTime()) / <span class="number">1000</span>)</span><br><span class="line">    <span class="keyword">var</span> timeStamp = timeStamp1.toString()</span><br><span class="line">    <span class="keyword">var</span> nonceStr = res.data.nonce_str</span><br><span class="line">    <span class="keyword">var</span> package = <span class="string">"prepay_id="</span> + res.data.prepay_id</span><br><span class="line">    <span class="keyword">var</span> signType = <span class="string">"MD5"</span></span><br><span class="line">    <span class="keyword">var</span> key = <span class="string">"Niskh5234234WYk4323HyE78m2sE"</span><span class="comment">//商户平台的key</span></span><br><span class="line">    <span class="keyword">var</span> sign = res.data.sign</span><br><span class="line">    <span class="keyword">var</span> paySign = md5.hexMD5(<span class="string">"appId="</span> + appId + <span class="string">"&amp;nonceStr="</span> + nonceStr + <span class="string">"&amp;package="</span> + package + <span class="string">"&amp;signType=MD5&amp;timeStamp="</span> + timeStamp + <span class="string">"&amp;key="</span> + key)</span><br><span class="line">    wx.requestPayment(&#123;</span><br><span class="line">      timeStamp: timeStamp,</span><br><span class="line">      <span class="comment">//随机字符串，长度为32个字符以下。</span></span><br><span class="line">      nonceStr: nonceStr,</span><br><span class="line">      <span class="comment">//统一下单接口返回的 prepay_id 参数值，提交格式如：prepay_id=*</span></span><br><span class="line">      package: package,</span><br><span class="line">      <span class="comment">//签名算法，暂支持 MD5</span></span><br><span class="line">      signType: <span class="string">'MD5'</span>,</span><br><span class="line">      paySign: paySign,</span><br><span class="line">      success: <span class="function"><span class="keyword">function</span> (<span class="params">res</span>) </span>&#123;</span><br><span class="line">      &#125;,</span><br><span class="line">      fail: <span class="function"><span class="keyword">function</span> (<span class="params">res</span>) </span>&#123;</span><br><span class="line">      &#125;,</span><br><span class="line">      complete: <span class="function"><span class="keyword">function</span> (<span class="params">res</span>) </span>&#123;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
    </div>

    <div>全文完。</div>
  </article>
  <div class="toc-container">
    
  <div id="toc" class="toc-article">
    <strong class="toc-title">目录</strong>
    <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#支付流程示意图"><span class="toc-text">支付流程示意图</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#jsAPI、jsSDK、小程序支付的对比-开发步骤"><span class="toc-text">jsAPI、jsSDK、小程序支付的对比(开发步骤)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#小程序调起支付-API-说明"><span class="toc-text">小程序调起支付 API 说明</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#预支付流程"><span class="toc-text">预支付流程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#发起支付"><span class="toc-text">发起支付</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#代码Demo"><span class="toc-text">代码Demo</span></a></li></ol>
  </div>


  </div>
</div>
<div class="copyright">
    <span>本作品采用</span>
    <a href="https://creativecommons.org/licenses/by/4.0/">知识共享署名 4.0 国际许可协议</a>
    <span>进行许可。 转载时请注明原文链接。</span>
</div>
<div class="share" style="width: 100%;">
  <!-- <img src="https://kevinofneu-blog-static.oss-cn-beijing.aliyuncs.com/static/2018-12-10-qrcode_for_gh_ffacf5722095_258.jpg" alt="Running Geek" style="margin: auto; display: block;"/>

  <div style="margin: auto; text-align: center; font-size: 0.8em; color: grey;">老铁们关注走一走，不迷路</div> -->

</div>

  
    <div class="post-nav">
      <div class="post-nav-item post-nav-next">
        
          <span>〈 </span>
          <a href="/2019/03/21/微信小程序分享/" rel="next" title="微信小程序打夯之旅(五)：分享 &amp; 分享到朋友圈">
          微信小程序打夯之旅(五)：分享 &amp; 分享到朋友圈
          </a>
        
      </div>
  
      <div class="post-nav-item post-nav-prev">
          
          <a href="/2019/03/28/微信小程序组件内容槽/" rel="prev" title="微信小程序打夯之旅(七)：组件支持多个内容槽(slot)">
            微信小程序打夯之旅(七)：组件支持多个内容槽(slot)
          </a>
          <span>〉</span>
        
      </div>
    </div>
  


    </div>

    
    <div id="vcomments" style="max-width: 800px; margin: 16px auto;"></div>
  </div>
  <footer class="footer text-center">
    <div id="bottom-inner">
        <a class="bottom-item" href="/">首页</a> |
        <a class="bottom-item" href="https://github.com/TJ-XiaJiaHao" target="_blank">GitHub</a> |
        <a class="bottom-item">联系邮箱：1452806@tongji.edu.cn</a>
    </div>
</footer>
  

<script>
  (function(window, document, undefined) {

    var timer = null;

    function returnTop() {
      cancelAnimationFrame(timer);
      timer = requestAnimationFrame(function fn() {
        var oTop = document.body.scrollTop || document.documentElement.scrollTop;
        if (oTop > 0) {
          document.body.scrollTop = document.documentElement.scrollTop = oTop - 50;
          timer = requestAnimationFrame(fn);
        } else {
          cancelAnimationFrame(timer);
        }
      });
    }

    var hearts = [];
    window.requestAnimationFrame = (function() {
      return window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        function(callback) {
          setTimeout(callback, 1000 / 60);
        }
    })();
    init();

    function init() {
      css(".heart{z-index:9999;width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
      attachEvent();
      gameloop();
      addMenuEvent();
    }

    function gameloop() {
      for (var i = 0; i < hearts.length; i++) {
        if (hearts[i].alpha <= 0) {
          document.body.removeChild(hearts[i].el);
          hearts.splice(i, 1);
          continue;
        }
        hearts[i].y--;
        hearts[i].scale += 0.004;
        hearts[i].alpha -= 0.013;
        hearts[i].el.style.cssText = "left:" + hearts[i].x + "px;top:" + hearts[i].y + "px;opacity:" + hearts[i].alpha + ";transform:scale(" + hearts[i].scale + "," + hearts[i].scale + ") rotate(45deg);background:" + hearts[i].color;
      }
      requestAnimationFrame(gameloop);
    }

    /**
     * 给logo设置点击事件
     * 
     * - 回到顶部
     * - 出现爱心
     */
    function attachEvent() {
      var old = typeof window.onclick === "function" && window.onclick;
      var logo = document.getElementById("logo");
      if (logo) {
        logo.onclick = function(event) {
          returnTop();
          old && old();
          createHeart(event);
        }
      }
      
    }

    function createHeart(event) {
      var d = document.createElement("div");
      d.className = "heart";
      hearts.push({
        el: d,
        x: event.clientX - 5,
        y: event.clientY - 5,
        scale: 1,
        alpha: 1,
        color: randomColor()
      });
      document.body.appendChild(d);
    }

    function css(css) {
      var style = document.createElement("style");
      style.type = "text/css";
      try {
        style.appendChild(document.createTextNode(css));
      } catch (ex) {
        style.styleSheet.cssText = css;
      }
      document.getElementsByTagName('head')[0].appendChild(style);
    }

    function randomColor() {
      // return "rgb(" + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + ")";
      return "#F44336";
    }

    function addMenuEvent() {
      var menu = document.getElementById('menu-main-post');
      if (menu) {
        var toc = document.getElementById('toc');
        if (toc) {
          menu.onclick = function() {
            if (toc) {
              if (toc.style.display == 'block') {
                toc.style.display = 'none';
              } else {
                toc.style.display = 'block';
              }
            }
          };
        } else {
          menu.style.display = 'none';
        }
      }
    }

  })(window, document);
</script>

  



</body>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
<script type="text/javascript">
  new Valine({
    el: '#vcomments',
    appId: '8CwYqXS8IoFbvaA9PmgqGjTf-gzGzoHsz',
    appKey: 'z5bVoSPDPhd8hzlXvDey5Hpz',
    verify:false,
    placeholder: '评论留言'
  })
</script>
</html>
